package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.SysProjectAlarm;
import com.ruoyi.system.mapper.SysProjectAlarmMapper;
import com.ruoyi.system.service.SysAlarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author ：zouRiRi
 * @Date ：Created in 2022/3/31 15:08
 */
@Service
public class SysAlarmServiceImpl implements SysAlarmService {
    @Autowired
    private SysProjectAlarmMapper sysProjectAlarmMapper;
    @Override
    public SysProjectAlarm selectAlarmByProjectId(Long projectId) {
        return sysProjectAlarmMapper.selectAlarmByProjectId(projectId);
    }

    @Override
    public void insertAlarmInformation(SysProjectAlarm sysProjectAlarm) {
        SysProjectAlarm ProjectAlarm = sysProjectAlarmMapper.selectAlarmByProjectId(sysProjectAlarm.getProgressId());
        if(ProjectAlarm!=null){
            Integer overTime = ProjectAlarm.getOverTime();
            if(overTime!=sysProjectAlarm.getOverTime()){
                sysProjectAlarmMapper.updateAlarmInformation(sysProjectAlarm.getOverTime(),ProjectAlarm.getId());
            }
        }else{
            sysProjectAlarmMapper.insertAlarmInformation(sysProjectAlarm);
        }
    }

    @Override
    public List<SysProjectAlarm> selectAlarmList() {
        return sysProjectAlarmMapper.selectAlarms();
    }

    @Override
    public void deleteAlarmInformation(Long id) {
        sysProjectAlarmMapper.deleteAlarm(id);
    }

}
